
package chasqui.servlets;


import conn.dao.DCampana;
import conn.dao.DLinea;
import java.io.IOException;
import java.util.ArrayList;

import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


public class ReportesServlet extends HttpServlet
{
    protected void doPost(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException
    {
        String action = request.getParameter("action");
        String jspPage = "/index.jsp";

        if ((action == null) || (action.length() < 1))
        {
            action = "default";
        }

        if ("default".equals(action))
        {
            jspPage = "/index.jsp";
        }
        else if ("busquedalineas".equals(action))
        {
            DLinea manager = new DLinea();
            List lineas = manager.getmodlineas();
            request.setAttribute("lineas", lineas);

            jspPage = "/busqueda_personalizada_lineas.jsp";
        }
        else if ("listreportes".equals(action))
        {
            String usuario = "";
            HttpSession sesionOk = request.getSession();
            if (sesionOk.getAttribute("usuario") == null) {
                String mensaje="Debe iniciar sesion!!!.";
                request.setAttribute("mensajeError", mensaje);
                jspPage="/usuario.jsp";}
            else {
                usuario = (String)sesionOk.getAttribute("usuario");
                request.setAttribute("usuario", usuario);




            DCampana dcampana = new DCampana();
            List campanas = new ArrayList();
            campanas = dcampana.getmodcampanas();
            request.setAttribute("campanas", campanas);

            jspPage = "/reportes.jsp";
            }
        }
        else if ("filteremployeelist".equals(action))
        {
   
            jspPage = "/employeeList.jsp";
        }
        
        dispatch(jspPage, request, response);
    }

    protected void dispatch(String jsp, HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException
    {
        if (jsp != null)
        {
            RequestDispatcher rd = request.getRequestDispatcher(jsp);
            rd.forward(request, response);
        }
    }

    protected void doGet(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException
    {
        doPost(request, response);
    }
}